package com.javasea.web.mapstruct.controller;

import com.javasea.web.mapstruct.entity.Order;
import com.javasea.web.mapstruct.entity.OrderVo;
import com.javasea.web.mapstruct.entity.Product;
import com.javasea.web.mapstruct.entity.User;
import com.javasea.web.mapstruct.mapper.OrderMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
//    子对象映射
    @GetMapping("/mapStructToSubVo")
    public void mapStructToSubVo() {
        //创建一个user对象
        User user = new User();
        user.setId(1).setEmail("1964327885@qq.com").setUserName("小慕")
            .setBirthday(new Date()).setTel("18772563087");
        //创建productList
        List<Product> productList = new ArrayList<>();
        productList.add(new Product().setCount(3));
        productList.add(new Product().setCount(7));
        Order order = new Order();
        order.setUser(user).setProductList(productList);
        OrderVo orderVo = OrderMapper.INSTANCE.convertToVo(order);
        System.out.println(orderVo);
    }
}
